namespace Ke.Bee.Shared.Models;

/// <summary>
/// API 响应
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Success"></param>
/// <param name="Message"></param>
/// <param name="Data"></param>
/// <param name="Code"></param>
/// <param name="Timestamp"></param>
public record ApiResponse<T>(
    bool Success,
    string? Message = null,
    T? Data = default,
    string? Code = null,
    DateTimeOffset Timestamp = default)
{
    public static ApiResponse<T> Ok(
        string? message = null,
        T? data = default,
        string? code = "SUCCESS")
        => new(true, message, data, code, DateTimeOffset.UtcNow);

    public static ApiResponse<T> Fail(
        string errorMessage,
        string? code = "ERROR")
        => new(false, errorMessage, default, code, DateTimeOffset.UtcNow);
}

/// <summary>
/// API 响应 非泛型版本
/// </summary>
/// <param name="Success"></param>
/// <param name="Message"></param>
/// <param name="Code"></param>
/// <param name="Timestamp"></param>
public record ApiResponse(
    bool Success,
    string? Message = null,
    string? Code = null,
    DateTimeOffset Timestamp = default)
{
    public static ApiResponse Ok(string? message = null, string? code = "SUCCESS")
        => new(true, message, code, DateTimeOffset.UtcNow);

    public static ApiResponse Fail(string errorMessage, string? code = "ERROR")
        => new(false, errorMessage, code, DateTimeOffset.UtcNow);
}